package com.bootdo.jiashan.service.impl;

import com.bootdo.common.utils.BeanCopierUtil;
import com.bootdo.common.utils.DateUtil;
import com.bootdo.jiashan.dao.ProductDao;
import com.bootdo.jiashan.domain.ProductDO;
import com.bootdo.jiashan.model.GoodsModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.bootdo.jiashan.dao.GoodsDao;
import com.bootdo.jiashan.domain.GoodsDO;
import com.bootdo.jiashan.service.GoodsService;
import org.springframework.util.CollectionUtils;

import static com.bootdo.common.utils.DateUtil.dateTimeFormatter;


@Service
public class GoodsServiceImpl implements GoodsService {

	@Autowired
	private GoodsDao goodsDao;
	@Autowired
	private ProductDao productDao;
	
	@Override
	public GoodsDO get(Integer id){
		return goodsDao.get(id);
	}
	
	@Override
	public List<GoodsModel> list(Map<String, Object> map){
		List<GoodsModel> modelList = goodsDao.list(map);
		if(!CollectionUtils.isEmpty(modelList)){
			modelList.forEach(goodsModel -> {
				goodsModel.setCtimeStr(DateUtil.getDateStrByFormatter(goodsModel.getCtime(),dateTimeFormatter));
				goodsModel.setTimeStr(DateUtil.getDateStrByFormatter(goodsModel.getTime(),dateTimeFormatter));
				modelList.add(goodsModel);
			});
		}
		return modelList;
	}
	
	@Override
	public int count(Map<String, Object> map){
		return goodsDao.count(map);
	}
	
	@Override
	public int save(GoodsDO goods){
		return goodsDao.save(goods);
	}
	
	@Override
	public int update(GoodsDO goods){
		return goodsDao.update(goods);
	}
	
	@Override
	public int remove(Integer id){
		return goodsDao.remove(id);
	}
	
	@Override
	public int batchRemove(Integer[] ids){
		return goodsDao.batchRemove(ids);
	}
	
}
